<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const compose = (...fns) => {
            // 注意 f、g 的位置，如果实现从左到右计算，则置换顺序
            return fns.reduce((f, g) => {
                return (...args) => f(g(...args))
            })
        }

        function reverse(array) {
            return array.reverse();
        }

        function first(array) {
            return array[0];
        }

        // 先反转，再获取第一个元素
        const last = compose(first, reverse)

        const arr = [1, 6, 8, 7, 9]
        console.log(last(arr));//9
    </script>
</body>

</html>